#ifndef QTLCDLABEL_H
#define QTLCDLABEL_H

#include <QLabel>
#include <QPainter>
#include <QPaintEvent>
#include <QImage>
#include <QTimer>

class QtLCDLabel : public QLabel
{
    Q_OBJECT
public:
    QtLCDLabel(QWidget *parent = nullptr);
    ~QtLCDLabel();

    void setText(QString text);
    void setPixelSize(int size)   { m_pixelSize = size; this->update();}
    void setSpacingSize(int size) { m_spacingSize = size; this->update();}
    void setTextColor(QColor color) { m_textColor = color; this->update();}
    void setPixelColor(QColor color) { m_pixelColor = color; this->update();}
    void setBackgroundColor(QColor color) { m_backgroundColor = color; this->update();}
    void setAutoScroll(bool flags);

protected:
    void paintEvent(QPaintEvent *pEvent);
    void resizeEvent(QResizeEvent *pEvent);
    QImage generateDotMatrix(const QString &text);
    QImage generateBackgroundDotMatrixImage();
    QImage generateDotMatrixImage(const QImage& source);

private:
    int m_scrollOffset = 0;
    QTimer *m_timer = nullptr;
    QImage m_textImage;
    QImage m_textDotMatrixImage;       // 绿色文字点阵图（提前生成好）
    QImage m_backgroundDotMatrixImage; // 灰色背景点阵图（只在resize时候生成一次）

    int m_pixelSize   = 2;
    int m_spacingSize = 1;

    QColor m_textColor = Qt::red;
    QColor m_pixelColor = QColor::fromRgb(32, 32, 32);
    QColor m_backgroundColor = Qt::black;

    bool m_IsAutoScroll = false;
};

#endif // QTLCDLABEL_H
